package com.licq.ldoc.parser.impl.annotation;

import java.lang.annotation.Annotation;

import net.sf.oval.constraint.Length;

import com.licq.ldoc.domain.Attribute;
import com.licq.ldoc.domain.AttributeType;
import com.licq.ldoc.parser.AnnotationParsee;

public class LengthAnnotationParsee extends AnnotationParsee {
	
	public LengthAnnotationParsee(AnnotationParsee successor) {
		super(successor);
	}

	@Override
	protected void doParse(Attribute attribute, Annotation annotation) {
		if (AttributeType.STRING == attribute.getType()) {
			Length length = (Length) annotation;
			StringBuffer comments = new StringBuffer();
			if (length.min() > 0 || length.max() != Integer.MAX_VALUE) {
				comments.append(getText());
				if (length.min() > 0) {
					comments.append(">=" + length.min());
				}
				if (length.max() != Integer.MAX_VALUE) {
					comments.append((length.min() > 0 ? " and " : "") + "<=" + length.max());
				}
			}
			attribute.appendComments(comments.toString());
		}
	}
	
}
